<template>
  <section>
   <section id="case-select-page">
      <w-row class="top">
        <w-cell direction="column" align="center">
            <img src='../../assets/img/search/banner.png'/>
            <span>醉强大脑</span>
        </w-cell>
      </w-row>
      <w-row class="bottom">
        <w-cell align="center">
           <w-button class="select-btn" bg-color="#f2f2f2" font-color="#a8a8a8" border-color="#dbd9d9" width="12rem" height="2.5rem" @click="getType(0)">凯特力吸入麻醉病例收集</w-button>
        </w-cell>
      </w-row>
       <w-row class="bottom">
         <w-cell align="center">
            <w-button class="select-btn" bg-color="#f2f2f2" font-color="#a8a8a8" border-color="#dbd9d9" width="12rem" height="2.5rem" @click="getType(1)">艾诺联合病例收集</w-button>
        </w-cell>
      </w-row>
   </section>
   <section class="case-menu">
     <case-menu :tag="2"></case-menu>
   </section>
  </section>
</template>
<script>
  import Vue from 'vue'
  import axios from 'axios'
  import { mapGetters, mapActions } from 'vuex';
  import caseMenu from '../../components/caseMenu';

  export default {
     name: 'caseSearch',
     data() {
       return {
         caseType: 0  
       }
     },
     props: {

     },
    components: {
      caseMenu
    },
    mounted() {
                // let openid = localStorage.openID;
                let wxobj = this.GetRequest(location.hash);
                let openid = wxobj["/caseselect?openid"];//oGqC5jgtFzCVXPrTQafjapEzX1iI;
                this.checkUserInfo(openid).then((response)=> {
                let _res = response[0];
                if(_res.msg == '0') { 
                    Wui.Toast.show('尚未注册，请先注册', 'middle');
                    setTimeout(function() {
                        location.href = '#/registtpl';
                    }, 1000);
                } else if(_res.msg == '1') {
                    var _user = JSON.stringify(_res.userInfo);
                    localStorage.setItem('userMsg', _user);

                    axios.get('/user/getdoctorinfo?openid='+openid+'', {}).then((res) => {
                      if(res.data.Result != "success") {
                        window.Wui.Toast.show(res.data.msg, 'middle');
                        setTimeout(function() {
                            Vue.prototype.$wx.closeWindow();
                        }, 1500);
                      }
                    });
                }

            })
  
    },
    methods: {
      ...mapActions([
            'checkUserInfo'

      ]),
      getType: function(tid) {
        if(tid == 0) {
           this.$router.push({name:'caseAdd',params: {}});
        } else {
           this.$router.push({name:'report',params: {}});
        }
      },
      GetRequest: function(url) {
                var url = decodeURI(url); //获取url中"?"符后的字串   
                var theRequest = {};
                if (url.indexOf("?") != -1) {   
                    var str = url.substr(1);   
                    let strs = str.split("&");   
                    for(var i = 0; i < strs.length; i ++) {   
                        theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
                    }   
                }  
                return theRequest;   
      } 
    }
  }
</script>

<style lang="scss" scoped>
  #case-select-page {
        display: flex;
        flex-direction: column;
        align-items: center;
        height: 360px;
        justify-content: space-around;
        align-items: center;
        padding-top: 2rem;
        font-size: 0.6rem;
      .top {
          img {
              width: 5.55rem;
          }
          span {
              margin-top: 0.5rem;
              font-size: 1.5rem;
          }
      }
      .case-search-msg {
              width: 80%;
              margin: 0 auto;
              border: 1px solid #e1e1e1;
              border-radius: 8px;
              margin-bottom: -0.6rem;
              background: #f2f2f2;
              padding: 0 0 0 1rem;
              button {
                  width: 2.025rem;
                  height: 1.875rem !important;
                  background: url('../../assets/img/search/search.png') center no-repeat;
                  background-size: 100% auto;
              }
      }
      .wui-field {
           background: none !important;
       }
       .wui-border-1px {
           position: static !important;
       }
       .wui-button:after {
        height: 0 !important;
        width: 0 !important;
       }
      .wui-border-1px:after {
          border: 0 !important;
       }
       .select-btn{
         font-size: 0.8rem;
       }
  }
</style>
 